<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
         $this->display();
    }
    public function login(){
         $this->display();
    }
    public function checkLogin(){
        session('flag',null);
        $code=I('post.verify');
        $adminflag=I('post.adminflag');
        if(!$this->check_verify($code))$this->error('验证码错误');
        if($adminflag =='2'){
        $admin=M('clubadmin');
        $map   =   array();
        $map['account']	= I('post.account');
        $map['password']	= md5(I('post.password'));
        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            session("flag","logok");
            redirect('cindex');
        }
    }else if($adminflag =='1'){
        $admin=M('superadmin');
        $map   =   array();
        $map['account'] = I('post.account');
        $map['password']    = md5(I('post.password'));
        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            session("flag","logok");
            redirect('sindex');
        }
    }
    }

     public function _initialize(){
        //只要不是显示登录页面和处理登录、验证码这些，其他情况都要进行session验证。
        if(ACTION_NAME!='index' && ACTION_NAME!='checkLogin'&& ACTION_NAME!='verify'){
            //redirect('index');
        }
    }

function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }

    public function verify(){

        ob_clean();
//        $config =    array(
//            'fontSize'    =>    30,    // 验证码字体大小
//            'length'      =>    3,     // 验证码位数
//            'useNoise'    =>    false, // 关闭验证码杂点
//            //'fontttf' => 'msyhbd.ttf',
//
//
//            'useImgBg' => false,
//            //'useZh' => true,
//        );
//        $Verify = new \Think\Verify($config);
        $Verify = new \Think\Verify();
        $Verify->entry();

    }
}